package com.dmz.oauth2.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

import com.dmz.oauth2.jwt.MyJwtAccessTokenConverter;

@Configuration
public class JwtTokenConfig {

    /**
     * 1:配置 JWT 数据转换
     * 设置解密的key
     * @return
     */
    @Bean("jwtAccessTokenConverter")
    public JwtAccessTokenConverter jwtAccessTokenConverter(){
        JwtAccessTokenConverter converter=new JwtAccessTokenConverter();
        //设置为解密token的key 同样在加密的时候也要设置为这个key
        converter.setSigningKey("123456");
        return converter;
    }
    
 
    
    /**
     * 2:返回jwt存储器
     * @return
     */
    @Bean("jwtTokenStore")
    public TokenStore jwtTokenStore(){
        return  new JwtTokenStore(jwtAccessTokenConverter());
    }
}